package com.ct.gd.passport.view.discount;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import com.ct.gd.passport.R;
import com.ct.gd.passport.common.constants.UmengVar;
import com.ct.gd.passport.domain.DiscountInfo;
import com.ct.gd.passport.view.BundleKeys;
import com.umeng.analytics.MobclickAgent;
import com.up91.common.android.view.adapter.SimpleListAdapter;

public class RootCatalogFragment extends DiscountInfoFragment{

	@Override
	protected SimpleListAdapter<DiscountInfo> onInitListAdapter() {
		return new RootCatalogListAdapter(getActivity(), null);
	}

	@Override
	public void onListItemClick(ListView l, View v, int position, long id) {
		DiscountInfo discountInfo = (DiscountInfo)l.getItemAtPosition(position);
		MobclickAgent.onEvent(getActivity(), UmengVar.TRAVEL_DISCOUNT_DETAIL);
		// enter detail
		Intent intent = new Intent(this.getActivity(), DiscountDetailActivity.class);
		intent.putExtra(BundleKeys.CATALOG_ID, discountInfo.getId());
		startActivity(intent);
	}
	public class RootCatalogListAdapter extends SimpleListAdapter<DiscountInfo> {

		private class ViewHolder {
			TextView	tvName;
		}

		public RootCatalogListAdapter(Context context, List<DiscountInfo> data) {
			super(context, data);
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			ViewHolder holder;
			if (null == convertView) {
				convertView = mInflater.inflate(R.layout.root_catalog_list_item, null);
				holder = new ViewHolder();
				holder.tvName = (TextView) convertView.findViewById(R.id.tv_root_catalog_name);
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}
			holder.tvName.setText(getData().get(position).getName());
			return convertView;
		}

	}
}
